package ua.kharkov.knure.dereza.summarytask4.command;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

/**
 * Contains all commands
 * 
 * @author dereza
 * 
 */
public class CommandContainer {

	private static final Logger log = Logger.getLogger(CommandContainer.class);

	private static Map<String, Command> commands = new HashMap<String, Command>();

	static {
		// common commands
		commands.put("login", new LoginCommand());
		commands.put("logout", new LogoutCommand());
		commands.put("viewSettings", new ViewSettingsCommand());
		commands.put("applySettings", new ApplySettingsCommand());
		commands.put("noCommand", new NoCommand());

		// client commands
		commands.put("clientListCards", new ClientListCardsCommand());
		commands.put("withdraw", new WithdrawCommand());
		commands.put("replenish", new ReplenishCommand());
		commands.put("lockCard", new LockCardCommand());
		commands.put("contactToAdmin", new ContactToAdminCommand());

		// admin commands
		commands.put("adminListCards", new AdminListCardsCommand());
		commands.put("unlockCard", new UnlockCardCommand());

		log.debug("Command container was successfully initialized");
		log.trace("Number of commands --> " + commands.size());
	}

	/**
	 * Returns command object with the given name.
	 * 
	 * @param commandName
	 * @return Command object.
	 */
	public static Command get(String commandName) {
		if (commandName == null || !commands.containsKey(commandName)) {
			log.trace("Command not found, name --> " + commandName);
			return commands.get("noCommand");
		}
		return commands.get(commandName);
	}
}
